//
// Created by 29019 on 2020/5/18.
//

#include "pattern/factory.hpp"
#include <iostream>
#include "pattern/adapter.hpp"
#include "threadsafe/thread_safe_list.hpp"

class Player{
public:
    virtual void Play(){
        return ;
    }
};
class MP3Player :public  Player{
    void Play(){
        std::cout<<"mp3 playing"<<std::endl;
        return ;
    }
};
class MP4Player :public  Player{
    void Play(){
        std::cout<<"mp4 playing"<<std::endl;
        return ;
    }
};
class BridgeTest :public Bridgeable<Player>{
public:
    BridgeTest(Player *mPlayer) {
        this->mBridgeData = mPlayer;
    }
    void Play(){
        this->mBridgeData->Play();
    }
private:
    BridgeTest(){

    }
};
/*
 显示调用
 */
using namespace std;
class Product :public CloneAble<Product>{
public:
    Product(){
        mAttribute1 = -1;
        mAttribute2 = '1';
    }
    Product *Clone(){
        Product *ret = new Product;
        ret->mAttribute1 = this->mAttribute1;
        ret->mAttribute2 = this->mAttribute2;
        return  ret;
    }
    void SetAttr1( char x){
        this->mAttribute1 = x;
    }
    void SetAttr2(char x){
        this->mAttribute2 = x;
    }
    void Show(){
        std::cout<<mAttribute1<<" "<<mAttribute2<<" "<<std::endl;
    }
private:
    int mAttribute1;
    char mAttribute2;
};
/*
 * mediater test
*/
class HandleData{
public:
    std::string data;
};
class Motherboard :public Mediator<HandleData>{
};
class RAM :public MediatorColleague<HandleData>{
public:
    RAM(std::string name,Mediator<HandleData> *p) : MediatorColleague(name,p){
    }
    int Send(std::string colleage,HandleData data){
        this->mMediater->Relay(colleage,data);
        return 0;
    }
    int Recv(std::string colleage,HandleData data){
        std::cout<<colleage<<this->mName<<" receive data "<<data.data<<endl;
        return 0;

    }
};
class SoundCard :public MediatorColleague<HandleData>{
public:
    SoundCard(std::string name,Mediator<HandleData> *p) : MediatorColleague(name,p){
    }
    int Send(std::string colleage,HandleData data){
        this->mMediater->Relay(colleage,data);
        return 0;
    }
    int Recv(std::string colleage,HandleData data){
        std::cout<<colleage<<this->mName<<" receive data "<<data.data<<endl;
        return 0;
    }
};
/*
 * mediater test end
*/

int main(){
    // Motherboard mon;
    // SoundCard soundcard("souncard",&mon);
    // RAM ram("ram",&mon);
    // mon.Register((MediatorColleague<HandleData>*) &soundcard);
    // mon.Register((MediatorColleague<HandleData>*) &ram);
    // soundcard.Send("ram",HandleData{"ss"});

    // BridgeTest br(new MP3Player);
    // BridgeTest br1(new MP4Player);

    // br.Play();
    // br1.Play();

    // Product *z = new Product;
    // z->SetAttr1(-11);
    // z->SetAttr2('c');
    // z->Show();

    // Prototype<Product> x(z);
    // delete(z);
    // // 即使delete掉了原型，也能接着使用
    // auto tbl3 = x.GetProduct();
    // tbl3->Show();

    // test threadsafe
    ThreadSafeList<std::string> m1;
    m1.PushBack("111");
    auto x = m1.Front();
    std::cout << x << " 1234er ";
    x = m1.Front();
    std::cout << x << " 1234er ";
    m1.PopFront();
    std::cout << m1.Length();
    x = m1.Front();
    std::cout << x << " 1234er1 ";
}
